﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_GetLatestEvents : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetLatestEvent();
            }
        }
        private void GetLatestEvent()
        {
            try
            {
                var events = FilStartUpsAPI.GetLatestEvent();
                dl_latestevent.DataSource = events;
                dl_latestevent.DataBind();
            }
            catch
            {

            }
        }
        protected void dl_latestevent_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "SelectRow")
            {
                Label lbeventidPK = (Label)dl_latestevent.Items[e.Item.ItemIndex].FindControl("lbeventid");
                Response.Redirect("~/Event.aspx?id=" + lbeventidPK.Text);
            }
        }
        public string Truncate(string desc)
        {
            string desc_;
            try
            {
                desc_=desc.ToString().Substring(0, 50) + "..."; 
            }
            catch
            {
                desc_ = desc;
            }
            return desc_;
        }

        public string ConvertDate(string date)
        {
            string date_;
            try
            {
                DateTime _date = Convert.ToDateTime(date);
                date_ = _date.ToShortDateString();//String.Format("{0:d/M/yyyy}", date);
            }
            catch
            {
                date_ = date.ToString();
            }
            return date_;
        }
        protected void btneventrss_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/rss.aspx?ID=3");
        }
    }
}